#include <iostream>
using std::cout;
using std::endl;

//不用返回一个局部变量的引用
//函数返回类型为引用时
//要确保其绑定的本体生命周期比函数更长
//类比指针函数进行理解
int num = 10;

int & func(){
    return num;
}



int & func2(){
    int * p = new int(30);
    /* cout << p << endl; */
    return *p;
}

void test0(){
    /* cout << func2() << endl; */
    /* func2() = 300; */
    /* cout << func2() << endl; */
    /* cout << &func2() << endl; */

    int & ref = func2();
    cout << ref << endl;
    ref = 300;
    cout << ref << endl;
    delete &ref;
}

int main(void){
    test0();
    return 0;
}
